/****************************************************************
 *This file is global.c
 ****************************************************************/

#include "include.h"

// 上位机指令和处理函数
pc_cmd_str pc_cmd_data[PC_COMMAND_NUM];

// 485load 函数
ViUInt32 	udp_load_count[MAX_FD_NUM];
ViChar	 	*udp_load_data_p[MAX_FD_NUM];

// 485 LOAD的请求标志和应答标志
ViUInt32    udp_load_flag[MAX_FD_NUM];
ViUInt32    ack_udp_load_flag[MAX_FD_NUM];

// 485 upload 函数
ViUInt32 	udp_upload_count[MAX_FD_NUM];
ViChar	 	*udp_upload_data_p[MAX_FD_NUM];

// 485 uplOAD的请求标志和应答标志
ViUInt32    udp_upload_flag[MAX_FD_NUM];
ViUInt32    ack_udp_upload_flag[MAX_FD_NUM];

// 高速通信的文件描述符和状态
unsigned int udp_socket_fd[MAX_FD_NUM];
unsigned int udp_socket_fd_two[MAX_FD_NUM];
unsigned int udp_socket_status[MAX_FD_NUM];

// 重映射AXI-LITE空间
int mmap_fd = 0;
unsigned char *mmap_addr = NULL;

// fifo 相关变量
Pfifo * fifo[_422_CHANNEL_NUM];

// 互斥锁
pthread_mutex_t myMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t spaceMutex = PTHREAD_MUTEX_INITIALIZER;

// 存储指令握手的变量
unsigned char command_buf[COMMAND_LEN][CONFIG_COMMAND_NUM];
unsigned char ack_command_buf[COMMAND_LEN][CONFIG_COMMAND_NUM];
unsigned int command_buf_len[CONFIG_COMMAND_NUM];
unsigned char ack_command_buf_len[CONFIG_COMMAND_NUM];

// 使能配置取数握手模式
unsigned int command_enable_mode = 0xaa;

// 读取pcm的数据缓冲区和长度
char pcm_rd_data_buffer[PCM_RD_LEN];
unsigned int pcm_rd_date_length;
unsigned int pcm_once_read_len = 256;

// 读取pcm的数据缓冲区和长度
char pcm_rd_data_buffer_two[PCM_RD_LEN];
unsigned int pcm_rd_date_length_two;
unsigned int pcm_once_read_len_two = 256;

// PCM存储的使用的变量
unsigned char pcm_one_store_buff_1[PCM_STORE_BUF_LEN];
unsigned int  pcm_one_store_len_1 = 0;
unsigned char pcm_one_store_buff_2[PCM_STORE_BUF_LEN];
unsigned int  pcm_one_store_len_2 = 0;
unsigned char pcm_one_use_channel = PCM_STORE_USE_ONE;

// PCM当前存储状态
unsigned char pcm_store_flag = PCM_STORE_USE_ONE;

// PCM存储使用的文件句柄
int pcm_store_fd = 0;

// PCM存储状态
unsigned char pcm_store_status = STOP_PCM_STORE;

// 开启启动监控标志
unsigned char start_system_monitor_flag = STOP_SYSTEM_MONITOR;

// PCM和日志存储总空间和已使用空间
unsigned int pcm_all_space = 0, pcm_use_space = 0;
unsigned int log_all_space = 0, log_use_space = 0;

// 创建日志文件标志
unsigned char create_log_name_flag = FLAG_INVALID;

// 日志存储使用的文件句柄
int log_store_fd = 0;

// 写日志sockfd
int sockfd_wr_log;
struct sockaddr_in server_addr_wr_log;

// 接收日志数据sockfd
int sockfd_command;
struct sockaddr_in server_addr_command;

// 接收系统日志数据缓存器
unsigned char rev_syslog_buf[REV_LOG_BUF_LEN];
unsigned int  rev_syslog_len;

// 存储长度
long long all_store_data_len = 0;
long long thread_pcm_store_len = 0;
long long single_store_len = 0;
long long sys_log_store_len = 0;
long long inter_log_time = 0;
long long inter_log_wr_time = 0;
long long inter_pcm_time = 0;
long long inter_pcm_wr_time = 0;

